with Ada.Assertions; use Ada.Assertions;

with GNAT.Regexp;
with GNAT.IO;

use GNAT;

separate(Test_Website_Retrieval)

--
-- test download of URL contents into Bounded String
--

procedure Test_Into_String
is

   --
   -- regex search for website title
   --

   Search_Txt_RegEx : constant Regexp.Regexp := Regexp.Compile(

         SITE_VALID_TXT,

         Case_Sensitive => true );

   Search_Result : Boolean := false;


begin

   -- set parameter

   Host_Address_Type.Delete( Host_Addr_Parm, 1,
                             Host_Address_Type.Length( Host_Addr_Parm ));

   Host_Address_Type.Append( Host_Addr_Parm, SITE );

   Assert( Host_Address_Type.To_String( Host_Addr_Parm ) = SITE,

           "URL bounded string parameter contents unexpected" );

   WebGet_Obj.Retrieve( Host_Address   => Host_Addr_Parm,
                        Output_Str_Arg => Downloaded_Content,
                        Verbose        => false );

   --
   -- test size
   --

   Assert( Output_String_Type.Length( Downloaded_Content ) =
             SITE_CONTENTS_LENGTH,

           "size of downloaded content varies from expected" );

   --
   -- test contents
   --

   Search_Result := Regexp.Match( Output_String_Type.To_String(

         Downloaded_Content ),

         Search_Txt_RegEx );

   if( Search_Result = false ) then

      IO.Put_Line( Ascii.LF
                   & "downloaded content is :"
                   & Ascii.LF
                   & Output_String_Type.To_String( Downloaded_Content ));

   end if;

   Assert( Search_Result,

           "text not found in downloaded content: "
           & SITE_VALID_TXT
           & Ascii.LF
           & "URL: "
           & Host_Address_Type.To_String( Host_Addr_Parm ));


end Test_Into_String;